package com.los;

import java.util.Optional;

/**
 * @program: java8
 * @description: 容器实战
 * @author: Yujuan
 * @create: 2018-06-29 14:12
 **/
public class OptionalInAction {
    public static void main(String[] args) {
        Optional.ofNullable(getInsuranceNameByOptional(null)).ifPresent(System.out::println);
    }

    private static String getInsuranceNameByOptional(Person person){
        return Optional.ofNullable(person)
                .flatMap(Person::getCar).flatMap(Car::getInsurance)
                .map(Insurance::getName).orElse("Unknown");
    }
}
